﻿Public Class DSChiTietSuDungTheForm
    Dim dt As DataTable    
    Dim parent_form As Form
    Dim MaTheTinDung As String
    Sub New(parent As Form, ma_the As String)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        parent_form = parent
        MaTheTinDung = ma_the
        dt = ChiTietSuDungTheDAO.GetAll(MaTheTinDung)
    End Sub
    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        Me.Dispose()
        parent_form.Show()
    End Sub

    Private Sub NganHangForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        lbMaTheTinDung.Text = MaTheTinDung
        dg.DataSource = dt
        dg.Columns("MaTheTinDung").HeaderText = "Mã Thẻ Tín Dụng"
        dg.Columns("SoTien").HeaderText = "Số Tiền"
        dg.Columns("ChiTiet").HeaderText = "Chi Tiết"
        dg.Columns("NgaySuDung").HeaderText = "Ngày Sử Dụng"
        dg.Columns("SoTien").DefaultCellStyle.Format = "N0"
        dg.Columns("ID").Visible = False        
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.Dispose()
    End Sub

    Private Sub btChiTietSuDung_Click(sender As System.Object, e As System.EventArgs) Handles btChiTietSuDung.Click
        Dim ct As New ChiTietSuDungTheForm(MaTheTinDung, dt)
        ct.ShowDialog()        
    End Sub

    Private Sub dg_CellDoubleClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dg.CellDoubleClick        
        Dim obj As New ChiTietSuDungThe
        With obj
            .ID = dt.Rows(dg.CurrentRow.Index).Item("ID")
            .ChiTiet = dt.Rows(dg.CurrentRow.Index).Item("ChiTiet").ToString()
            .MaTheTinDung = dt.Rows(dg.CurrentRow.Index).Item("MaTheTinDung").ToString()
            .NgaySuDung = dt.Rows(dg.CurrentRow.Index).Item("NgaySuDung").ToString()
            .SoTien = dt.Rows(dg.CurrentRow.Index).Item("SoTien")
        End With
        Dim ct As New ChiTietSuDungTheForm(MaTheTinDung, dt, obj)
        ct.ShowDialog()
    End Sub

    Private Sub btReset_Click(sender As System.Object, e As System.EventArgs) Handles btReset.Click
        dt.DefaultView.RowFilter = ""
    End Sub

    Private Sub btTimKiem_Click(sender As System.Object, e As System.EventArgs) Handles btTimKiem.Click
        Dim filter As String = ""        
        If txtChiTiet.Text.Trim <> "" Then
            filter = String.Format("chitiet like '%{0}%'", txtChiTiet.Text)
        End If
        If txtThang.Text.Trim() <> "" Then
            If filter.Trim() <> "" Then
                filter = " and "
            End If
            filter = filter & String.Format("CONVERT(ngaysudung,'System.String') LIKE '%/{0}/%'", txtThang.Text)
        End If
        If txtNam.Text.Trim() <> "" Then
            If filter.Trim() <> "" Then
                filter = " and "
            End If
            filter = filter & String.Format("CONVERT(ngaysudung,'System.String') LIKE '%/{0}'", txtNam.Text)
        End If
        dt.DefaultView.RowFilter = filter

    End Sub
End Class